﻿CREATE FUNCTION [audit].[GetTraceReturnCodeValue]
(@ReturnCode INT)
RETURNS NVARCHAR (256)
AS
BEGIN
	DECLARE @ReturnValue nvarchar(256)

	SELECT @ReturnValue = CASE @ReturnCode
			WHEN 0 THEN N'No error.'
			WHEN 1 THEN N'Unknown error.'
			WHEN 2 THEN N'The trace is currently running. Changing the trace at this time will result in an error.'
			WHEN 3 THEN N'The specified Event is not valid. The Event may not exist or it is not an appropriate one for the store procedure.'
			WHEN 4 THEN N'The specified Column is not valid.'
			WHEN 5 THEN N'The specified Column is not allowed for filtering. This value is returned only from sp_trace_setfilter.'
			WHEN 6 THEN N'The specified Comparison Operator is not valid.'
			WHEN 7 THEN N'The specified Logical Operator is not valid.'
			WHEN 8 THEN N'The specified Status is not valid.'
			WHEN 9 THEN N'The specified Trace Handle is not valid.'
			WHEN 10 THEN N'Invalid options. Returned when options specified are incompatible.'
			WHEN 11 THEN N'The specified Column is used internally and cannot be removed.'
			WHEN 12 THEN N'File not created.'
			WHEN 13 THEN N'Out of memory. Returned when there is not enough memory to perform the specified action.'
			WHEN 14 THEN N'Invalid stop time. Returned when the stop time specified has already happened.' 
			WHEN 15 THEN N'Invalid parameters. Returned when the user supplied incompatible parameters.'
			WHEN 16 THEN N'The function is not valid for this trace.'
			ELSE N'Invalid return code (' + CAST(@ReturnCode As nvarchar) + ').'
		END

	RETURN(@ReturnValue)
END